package kliment.flex.mx.controls {
	import mx.controls.ComboBox;
	import mx.core.ClassFactory;
	import mx.events.FlexEvent;

	public class ComboBoxExt extends ComboBox {
		public function ComboBoxExt() {
			super();

			dropdownFactory = new ClassFactory(ListExt);
			itemRenderer = new ClassFactory(LabelExt);
		}

		override public function set dataProvider(value:Object):void {
			super.dataProvider = value;
			_moveToEnable();
		}
		
		private function _moveToEnable():void {
			var i:int = -1;
			for each (var obj:Object in dataProvider) {
				i++;
				if (selectedIndex == -1) 
					selectedIndex = 0;
				
				if (i < selectedIndex) 
					continue;

				if (obj && ((obj is XML && obj.@enabled == 'false') || obj.enabled==false || obj.enabled=='false')){
					if(i == selectedIndex) {
						selectedIndex++;
					}
				}
			}
			if (selectedIndex > i) 
				selectedIndex = 0;
		}

		override public function initialize():void {
			toolTip = text;
			if (initialized)
				return;
			createChildren();
			super.initialize();
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth, unscaledHeight);
			toolTip = text;
		}
		
	}
}
